﻿using System;
using System.Collections.Generic;
using ProjScan.Config;
using ProjScan.RecordManager;
using ProjScan.ScanRule;
using ProjScan.ScanRule.Attr;
using ProjScan.Tools;
using UnityEditor;

namespace ProjScan.Modules
{
	// Token: 0x02000304 RID: 772
	internal class BasicAssetsFixModule : BaseModules<BasicAssetsFixModule, BasicAssetsCheckConfig>
	{
		// Token: 0x06001243 RID: 4675 RVA: 0x00054E90 File Offset: 0x00053090
		public override void Init()
		{
			this.ruleAttr = typeof(BasicAssetsRuleAttr);
			this.config = (Singleton<ConfigMgr>.Instance.GetConfig<BasicAssetsCheckConfig>() as BasicAssetsCheckConfig);
			bool flag = this.baseRules_Fix == null;
			if (flag)
			{
				this.baseRules_Fix = new List<BaseRule>();
			}
			else
			{
				this.baseRules_Fix.Clear();
			}
			this.recordRules_Fix.Clear();
			this.globalRules_Fix.Clear();
			RecordManagerFactory.Instance.Init();
		}

		// Token: 0x06001244 RID: 4676 RVA: 0x00054F10 File Offset: 0x00053110
		public override void Fix()
		{
			FixLog.Instance.Log(Module.Basic_Assets_Fix);
			this.Init();
			this.LoadRules(LoadMode.FixModules);
			this.LoadFixers();
			bool flag = this.baseRules_Fix == null || this.baseRules_Fix.Count == 0;
			if (flag)
			{
				ScanLog.Instance.LogInfo(Module.Basic_Assets_Fix, ScanLog.Stage.s2, "Rules is empty");
				ScanLog.UnityLogError("基本资源修复运行失败：相关规则全部关闭");
				this.Close();
			}
			else
			{
				for (int i = 0; i < this.recordRules_Fix.Count; i++)
				{
					RecordRule recordRule = this.recordRules_Fix[i];
					recordRule.FixRule();
					string fullName = recordRule.GetType().FullName;
					FailedResultManager.Instance.UpdateFailedData(fullName, recordRule.failAssetInfos);
					this.UpdateFailedData(recordRule);
				}
				this.Close();
			}
		}

		// Token: 0x06001245 RID: 4677 RVA: 0x00054FE8 File Offset: 0x000531E8
		public override void Close()
		{
			AssetDatabase.SaveAssets();
			ToolsHelper.ClearProgressBar();
			Singleton<PerformanceMeasurer>.Instance.CloseAndRecordState();
			Singleton<PerformanceMeasurer>.Instance.AddExecutionCheckpoint("BasicAssetsFixEnd");
			FailedResultManager.Instance.SaveAll();
			ScanLog.Instance.LogInfo(Module.Basic_Assets_Fix, ScanLog.Stage.s6, "Done.");
		}

		// Token: 0x06001246 RID: 4678 RVA: 0x0005503C File Offset: 0x0005323C
		public override void FixSingle(string ruleId)
		{
			FixLog.Instance.OpenFixLog(false);
			FixLog.Instance.Log(Module.Basic_Assets_Fix);
			Singleton<PerformanceMeasurer>.Instance.PushState("BasicAssetsSingleFix");
			this.Init();
			this.LoadRules(LoadMode.FixSingle, ruleId);
			this.LoadFixers();
			bool flag = this.baseRules_Fix == null || this.baseRules_Fix.Count == 0;
			if (flag)
			{
				ScanLog.Instance.LogInfo(Module.Basic_Assets_Fix, ScanLog.Stage.s2, "Rules is empty");
				ScanLog.UnityLogError("基本资源修复运行失败：相关规则全部关闭");
				this.Close();
			}
			else
			{
				for (int i = 0; i < this.recordRules_Fix.Count; i++)
				{
					RecordRule recordRule = this.recordRules_Fix[i];
					recordRule.FixRule();
					this.UpdateFailedData(recordRule);
				}
				FixLog.Instance.CloseFixLog();
				this.Close();
			}
		}
	}
}
